package com.afkt.project.slice;

import com.afkt.project.ui.slice.*;
import com.afkt.project.util.ToastUtil;
import com.ohos.afkt.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.utils.IntentConstants;

/**
 * 其他功能主页面的slice
 */
public class OtherSlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_other);
        iniClick();
    }

    private void iniClick() {
        //事件/广播监听（网络状态、屏幕旋转等)
        findComponentById(ResourceTable.Id_one_one).setClickedListener(component -> present(new ListenerSlice(), new Intent()));

        //通知栏监听服务(NotificationService)
        findComponentById(ResourceTable.Id_one_two).setClickedListener(component -> present(new NotificationServiceSlice(), new Intent()));

        //无障碍监听服务
        findComponentById(ResourceTable.Id_one_three).setClickedListener(component -> present(new AccessibilityListenerServiceSlice(), new Intent()));

        //Wifi相关(热点)
        findComponentById(ResourceTable.Id_one_four).setClickedListener(component -> present(new WifiSlice(), new Intent()));

        //铃声、震动、通知栏等功能
        findComponentById(ResourceTable.Id_one_five).setClickedListener(component -> present(new RingtoneSlice(), new Intent()));

        //TimeManager定时器工具类
        findComponentById(ResourceTable.Id_one_six).setClickedListener(component -> present(new TimerSlice(), new Intent()));

        //DevCache
        findComponentById(ResourceTable.Id_one_seven).setClickedListener(component -> present(new DevCacheSlice(), new Intent()));

        //DevLogger
        findComponentById(ResourceTable.Id_one_eight).setClickedListener(component -> present(new DevLoggerSlice(), new Intent()));

        //日志、异常文件记录保存
        findComponentById(ResourceTable.Id_one_nine).setClickedListener(component -> present(new SaveFileSlice(), new Intent()));

        //崩溃日志捕获
        findComponentById(ResourceTable.Id_one_ten).setClickedListener(component -> present(new CrashLogSlice(), new Intent()));

        //路径信息
        findComponentById(ResourceTable.Id_eleven).setClickedListener(component -> present(new PathInformationSlice(), new Intent()));

        //webView辅助类
        findComponentById(ResourceTable.Id_one_twelve).setClickedListener(component -> present(new WebViewSlice(), new Intent()));

        //添加联系人
        findComponentById(ResourceTable.Id_one_fourteen).setClickedListener(component -> {
            ToastUtil.toastShowLong(this,"暂时启用联系人\n项目组提供方案！",ToastUtil.TOAST_SHORT_TIME);
            Intent intent = new Intent();
            Operation operation = new Intent.OperationBuilder().withDeviceId("").withAction("ability.intent.CONTACTS_ACTION").build();
            intent.setOperation(operation);
            IntentParams intentParams = new IntentParams();
            intentParams.setParam("PageFlag","page_flag_save_contact");
            intentParams.setParam("phoneNumber","188888888888");
            intent.setParams(intentParams);
            startAbility(intent);
        });

        //StartActivityForResult Callback 下的选择图片
        findComponentById(ResourceTable.Id_one_thirteen).setClickedListener(component -> present(new SelectPictureSlice(), new Intent()));

        //手机壁纸
        findComponentById(ResourceTable.Id_one_fifteen).setClickedListener(component -> present(new WallPaperSlice(), new Intent()));

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

}
